﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BitPortal.Business;
using BitPortal.Models;
using BitPortal.Utils;

namespace BitPortal.Modules.NewsList
{
    public partial class NewsList : Controls.BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            bool? IsHot = Convert.ToBoolean(ReferenceModule.GetModuleConfig("IsHot")) ? (bool?)true : null;
            int NumberOfArticles = ReferenceModule.GetModuleConfig("NumberOfArticles").ToInt32TryParse();
            int ArticlesPerPage = ReferenceModule.GetModuleConfig("ArticlesPerPage").ToInt32TryParse();
            int? Category = Request.QueryString["ArticleCategoryID"].ToInt32TryParse();
            if (Category == 0) { Category = ReferenceModule.GetModuleConfig("Category").ToInt32TryParse(); }
            if (Category > 0)
            {
                this.ltrTitle.Text = ArticleCategoryBLL.GetByID((int)Category).Name;
            }
            else
            {
                Category = null;
                this.ltrTitle.Text = ReferenceModule.GetModuleConfig("Header").ToString();
            }
            Pager1.PageSize = ArticlesPerPage;
            IQueryable<Article> ListArticle = ArticleBLL.GetByCondition<Int64>( categoryID: Category, isApproved:true, isEnabled:true, isHot: IsHot, start: NumberOfArticles > 0 ? 0 : -1, limit: NumberOfArticles > 0 ? NumberOfArticles : -1,searchFromChilds:true);
  
            Pager1.DataSource = ListArticle.ToList();
            Pager1.BindToControl = RptArticles;
            RptArticles.DataSource = Pager1.DataSourcePaged;
        }


    }
}